﻿using ConsoleApp1.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
	//初始化数据库，已有便删除不会在建
    public class DbInitalizer : System.Data.Entity.DropCreateDatabaseAlways<Admin1000Context>
    {
        protected override void Seed(Admin1000Context context)
        {
			//上下文中的内容/添加
			var product1 = new Product
			{
				ProductName = "飞鹤超级飞帆",
				Price = 269.0m
			};
            var product2 = new Product
            {
                ProductName = "合生元贝塔星",
                Price = 138.0m
            };

            context.Products.Add(product1);
            context.Products.Add(product2);
            context.SaveChanges();

			//商品1的库存
            var stock1 = new Stock
            {
                ProductId = product1.Id,
                StockNumber = 1000
            };

			//商品2的库存
            var stock2 = new Stock
            {
                ProductId = product2.Id,
                StockNumber = 2000
            };
            context.Stocks.Add(stock1);
            context.Stocks.Add(stock2);
            context.SaveChanges();

			//出售的数量
            var market1 = new Market
            {
                ProductId = product1.Id,
                StockId = stock1.Id,
                SellNumber = 500,
                SellPrice = 500 * product1.Price
            };


            var market2 = new Market
            {
                ProductId = product2.Id,
                StockId = stock2.Id,
                SellNumber = 100,
                SellPrice = 100 * product1.Price
            };
            context.Markets.Add(market1);
            context.Markets.Add(market2);
            context.SaveChanges();

            base.Seed(context);
        }
    }
}
